//
//  mainpage.m
//  hw3
//
//  Created by fcbayern on 2020/12/5.
//  Copyright © 2020 fcbayern. All rights reserved.
//

#import "mainpage.h"
#import "AFNetworking.h"
#import "Masonry.h"
#import "imagepage.h"


@interface mainpage ()
@property (strong,nonatomic)UILabel * name;
@property (strong,nonatomic)UILabel * level;
@property (strong,nonatomic)UILabel * email;
@property (strong,nonatomic)UILabel * phone;
@property (strong,nonatomic)UILabel * lname;
@property (strong,nonatomic)UILabel * llevel;
@property (strong,nonatomic)UILabel * lemail;
@property (strong,nonatomic)UILabel * lphone;
@property (strong,nonatomic)UIButton * Next;
@end

@implementation mainpage

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人信息";
    self.view.backgroundColor = [UIColor whiteColor];
    NSString * url = @"http://172.18.176.202:3333/hw3/getinfo?name=MOSAD";
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager GET:url parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary * getjson = (NSDictionary *)responseObject;
        [self setUI];
        self->_name.text = getjson[@"name"];
        self->_level.text = getjson[@"level"];
        self->_email.text = getjson[@"email"];
        self->_phone.text = getjson[@"phone"];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    // Do any additional setup after loading the view.
}

-(void)setUI{
    _name = [[UILabel alloc]init];
    _level = [[UILabel alloc]init];
    _email = [[UILabel alloc]init];
    _phone = [[UILabel alloc]init];
    _lname = [[UILabel alloc]init];
    _llevel = [[UILabel alloc]init];
    _lemail = [[UILabel alloc]init];
    _lphone = [[UILabel alloc]init];
    _Next = [[UIButton alloc] init];
    
    
    [self.view addSubview:_name];
    [self.view addSubview:_level];
    [self.view addSubview:_email];
    [self.view addSubview:_phone];
    [self.view addSubview:_lname];
    [self.view addSubview:_llevel];
    [self.view addSubview:_lemail];
    [self.view addSubview:_lphone];
    [self.view addSubview:_Next];
    [_Next setTitle:@"下一页" forState:UIControlStateNormal];
    _Next.font = [UIFont systemFontOfSize:20];
    [_Next setTitleColor:[UIColor colorWithRed: 0/ 255.0 green:191 / 255.0 blue:255 / 255.0 alpha:1] forState:UIControlStateNormal];
    _Next.layer.cornerRadius = 10;
    _Next.layer.borderWidth = 1;
    [_Next addTarget:self action:@selector(nextpage:) forControlEvents:UIControlEventTouchUpInside];
    _name.layer.cornerRadius = 10;
    _level.layer.cornerRadius = 10;
    _email.layer.cornerRadius = 10;
    _phone.layer.cornerRadius = 10;
    
    _name.layer.borderWidth = 1;
    _level.layer.borderWidth = 1;
    _email.layer.borderWidth = 1;
    _phone.layer.borderWidth = 1;
    _lname.text = @"姓名";
    _llevel.text = @"等级";
    _lemail.text = @"邮箱";
    _lphone.text = @"电话";
    _name.font = [UIFont systemFontOfSize:20];
    _level.font = [UIFont systemFontOfSize:20];
    _phone.font = [UIFont systemFontOfSize:20];
    _email.font = [UIFont systemFontOfSize:20];
    _name.textAlignment = UITextAlignmentCenter;
    _phone.textAlignment = UITextAlignmentCenter;
    _email.textAlignment = UITextAlignmentCenter;
    _level.textAlignment = UITextAlignmentCenter;
    [_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(self.view.frame.size.height*0.2);
        make.left.equalTo(_lname.mas_right).with.offset(self.view.frame.size.width*0.05);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.6);
    }];
    [_level mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_name.mas_bottom).with.offset(self.view.frame.size.height*0.1);
        make.left.equalTo(_llevel.mas_right).with.offset(self.view.frame.size.width*0.05);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.6);
    }];
    
    [_email mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_level.mas_bottom).with.offset(self.view.frame.size.height*0.1);
        make.left.equalTo(_lemail.mas_right).with.offset(self.view.frame.size.width*0.05);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.6);
    }];
    [_phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_email.mas_bottom).with.offset(self.view.frame.size.height*0.1);
        make.left.equalTo(_lphone.mas_right).with.offset(self.view.frame.size.width*0.05);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.6);
    }];
    
    [_lname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(self.view.frame.size.height*0.2);
        make.left.equalTo(self.view).with.offset(self.view.frame.size.width*0.1);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.2);
    }];
    [_llevel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_name.mas_bottom).with.offset(self.view.frame.size.height*0.1);
        make.left.equalTo(self.view).with.offset(self.view.frame.size.width*0.1);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.2);
    }];
    
    [_lemail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_level.mas_bottom).with.offset(self.view.frame.size.height*0.1);
        make.left.equalTo(self.view).with.offset(self.view.frame.size.width*0.1);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.2);
    }];
    [_lphone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_lemail.mas_bottom).with.offset(self.view.frame.size.height*0.1);
        make.left.equalTo(_lemail);
        make.height.equalTo(self.view.mas_width).multipliedBy(0.1);
        make.width.equalTo(self.view.mas_width).multipliedBy(0.2);
    }];
    [_Next mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(_lphone.mas_bottom).with.offset(self.view.frame.size.height*0.1);
           make.centerX.equalTo(self.view);
           make.height.equalTo(self.view.mas_width).multipliedBy(0.2);
           make.width.equalTo(self.view.mas_width).multipliedBy(0.4);
    }];
    
}
-(void)nextpage:(id)sender{
    imagepage * nextpage = [[imagepage alloc]init];
    [self.navigationController pushViewController:nextpage animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
